﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace Rizmar
{
    public partial class PesquisaUsuarioForm : Form
    {
        UsuarioForm parent;

        public PesquisaUsuarioForm(UsuarioForm referrer)
        {
            InitializeComponent();
            parent = referrer;
        }

        private void PesquisaUsuarioForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'rizmarDataSet.Usuario' table. You can move, or remove it, as needed.
            this.usuarioTableAdapter.Fill(this.rizmarDataSet.Usuario);
            this.pesquisaTextBox.Focus();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            parent.setUserName(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
            parent.setPassword("senhadificil");
            parent.setAdmin(bool.Parse(dataGridView1.SelectedRows[0].Cells[2].Value.ToString()));

            this.Close();
        }

        private void cancelarButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pesquisaTextBox_TextChanged(object sender, EventArgs e)
        {
            string selectCommand = "SELECT usuario, admin FROM [Usuario] WHERE usuario LIKE '" + pesquisaTextBox.Text + "%'";

            SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommand, ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            usuarioBindingSource.DataSource = table;
        }
    }
}
